<template>
    <div>
        <input v-model="name" type="text" @keyup.enter="addStudent" />
    </div>
</template>

<script setup>
import { ref } from 'vue';

const emit = defineEmits(['add']);

let name = ref(''); // v-model绑定的属性

const addStudent = () => {
    emit('add', name.value);
    console.log(name.value)
    name.value = ''; //文本框清空
}
</script>

<!-- <script>
import { ref } from 'vue';
export default {
    emits:['add'],
    setup(props, content) {
        let name = ref('');
        const addStudent = () => {
            // content里面：attrs、slots、emit
            content.emit('add', name.value);
            console.log(name.value)
            name.value = '';//文本框清空
        }
        return {
            name,
            addStudent
        }
    }
}
</script> -->